#!/bin/bash

# Exit immediately if a command exits with a non-zero status
set -e

# Define the build directory
SCRIPT_DIR="$(cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P)"
PROJECT_DIR="${SCRIPT_DIR}/.."
BUILD_DIR="${PROJECT_DIR}/build"

# Create the build directory if it doesn't exist
if [ ! -d "$BUILD_DIR" ]; then
    mkdir $BUILD_DIR
else
    rm -rf ${BUILD_DIR}/*
fi

# Navigate into the build directory
cd $BUILD_DIR

# Run CMake to configure the project
cmake ..

# Build the project
make

# Optionally, run tests if you have them and CMakeLists.txt is set up for it
# make test

# Navigate back to the project root directory
cd ..

echo "Build completed successfully."
